package rawengine.timer;

public class TimeAccumulator {
	
	private TimeHandler timeHandler;
	private long timeLimit;
	private long timeAccum;
	
	public TimeAccumulator()
	{
		timeAccum = 0;
		timeLimit = 0;
	}
	
	public void init(TimeHandler timeHandler, long timeLimit)
	{
		timeAccum		  	  = 0;
		this.timeLimit		  = timeLimit;
		this.timeHandler  	  = timeHandler;
	}
	
	public void init(TimeHandler timeHandler)
	{
		timeAccum		  = 0;
		this.timeHandler  = timeHandler;
	}
	
	public long getTimeAccum() {
		return timeAccum;
	}

	public void setTimeAccum(long timeAccum) {
		this.timeAccum = timeAccum;
	}

	public long getTimeLimit() {
		return timeLimit;
	}

	public void setTimeLimit(long timeLimit) {
		this.timeLimit = timeLimit;
	}

	public void update()
	{
		if(timeHandler != null)
		{
			timeAccum += timeHandler.getFrameTime();
		}
	}

	public void restart()
	{
		timeAccum %= timeLimit;
	}

	public boolean ended()
	{
		return timeAccum >= timeLimit;
	}

}
